﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.Objects.DataClasses;
using System.ComponentModel;
using System.Reflection;
using System.Data.Objects;
using MetadataBasedConfigArch.Framework.Entity;
using MetadataBasedConfigArch.Framework;

namespace MetadataBasedConfigArch.Model
{
    public abstract class CTXEntityObject: TableConfigurableEntityObject, IStaticConstrainable //:EntityObject
    {        
        #region Ctors

        public CTXEntityObject()
        {
            Type type = this.GetType();
            List<string> allStaticConstraintPropertyNames = StaticConstraintHelper.GetStaticConstraintPropertyNames(type);
            foreach (string propertyName in allStaticConstraintPropertyNames)
            {
                PropertyInfo propertyInfo = type.GetProperty(propertyName);
                if (propertyInfo != null)
                {
                    propertyInfo.SetValue(this, StaticConstraintHelper.GetStaticConstraintPropertyValue(propertyName), null);
                }
            }
        }

        #endregion

        #region IStaticConstrainable Members

        public bool IsStaticConstraintProperty(string propertyName)
        {
            return StaticConstraintHelper.GetStaticConstraintPropertyNames(this.GetType()).Contains(propertyName);
        }

        public TPropertyValue GetStaticConstraintPropertyValue<TPropertyValue>(string propertyName)
        {
            return (TPropertyValue)(StaticConstraintHelper.GetStaticConstraintPropertyValue(propertyName) ?? default(TPropertyValue));
        }

        #endregion
    }     

    #region Class Template
     
    public partial class CTXA : CTXEntityObject
    {
        //Generated By Code
        static CTXA()
        {
            StaticConstraintHelper.EnsureVerify<CTXA>();
        }
        //End
         

        public static CTXA Create(Int64 tenantID)
        {
            CTXA ctxa = new CTXA();
            ctxa.TenantID = tenantID;
            return ctxa;
        }

        public Int64 TenantID
        {
            get;
            // Generated By Code
            protected set;//End 
        }
    }

    #endregion
}
